package cn.zzuli.lianxiyi;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    String   strUrl="http://www.zzuli.edu.cn/_upload/article/images/34/fc/c60c302f447b91a0bd91092acb81/54fdf378-fe79-4d7a-a573-6adda84b617a.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView=findViewById(R.id.iv_pic);
         new Thread(){
              public  void run(){
                  try {
                      URL url=new URL(strUrl);
                      HttpURLConnection conn= (HttpURLConnection) url.openConnection();
                      InputStream inputStream=conn.getInputStream();
                      Bitmap  bitmap= BitmapFactory.decodeStream(inputStream);
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                             imageView.setImageBitmap(bitmap);
                          }
                      });
                  } catch (MalformedURLException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }

              }
         }.start();
    }
}